﻿@using ZKEACMS.Common.Models
@using Microsoft.AspNetCore.Html
@model ZKEACMS.Common.ViewModels.NavigationWidgetViewModel
@{
    NavigationEntity homePage = Model.Navigations.FirstOrDefault(m => m.ParentId == "#");
    if (homePage == null)
    {
        return;
    }
}
<div class="navigation">
    <div class="navbar navbar-default @((Model.Widget.IsTopFix??false)?"navbar-fixed-top":"")" role="navigation">
        <div class="@(Model.Widget.CustomerClass??"container")">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @if (Model.Widget.Logo.IsNotNullAndWhiteSpace())
                {
                    <a class="navbar-brand" href="~/">
                        @if (Model.Widget.Logo.IsNotNullAndWhiteSpace())
                        {
                            <img src="@Url.Content(Model.Widget.Logo)" alt="logo" class="logo" />
                        }
                    </a>
                }
                @{
                    <ul class="nav navbar-nav nav-mobile visible-xs">
                      @foreach (var item in Model.Navigations.Where(m => m.IsMobile ?? false))
                      {
                        <li class="pull-left @(item.IsCurrent ? "active" : "")">
                            @Html.SmartLink(Url.PathContent(item.Url), item.Title)
                        </li>
                      }
                    </ul>
                }
            </div>
            <div class="navbar-collapse collapse navbar-responsive-collapse">
                <ul class="nav navbar-nav @Model.Widget.AlignClass">
                    @foreach (NavigationEntity item in Model.Navigations.Where(m => m.ParentId == "#"))
                    {
                        if (Model.Navigations.Any(m => m.ParentId == item.ID))
                        {
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown">@item.Title <b class="caret"></b></a>
                                @if (Model.Navigations.Any(m => m.ParentId == item.ID))
                                {
                                    <ul class="dropdown-menu">
                                        @foreach (NavigationEntity child in Model.Navigations.Where(m => m.ParentId == item.ID))
                                        {
                                            IEnumerable<NavigationEntity> children = Model.Navigations.Where(m => m.ParentId == child.ID);
                                            if (children.Any())
                                            {
                                                <li class="dropdown hoveropen">
                                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">@child.Title <b class="caret right"></b></a>
                                                    @*@DropDown(children)*@
                                                </li>
                                            }
                                            else
                                            {
                                                <li class="@(child.IsCurrent ? "active" : "")">
                                                    @Html.SmartLink(Url.PathContent(child.Url), child.Title)
                                                </li>
                                            }
                                        }
                                    </ul>
                                }
                            </li>

                        }
                        else
                        {
                            <li class="@(item.IsCurrent ? "active" : "")">
                                @Html.SmartLink(Url.PathContent(item.Url), item.Title)
                            </li>
                        }
                    }
                </ul>
            </div>
        </div>
    </div>
</div>